package com.eurobcoin.manager;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.eurobcoin.helper.SqlSessionFactoryConfigurer;

public class DAOManager {

	private static final Logger logger = LoggerFactory.getLogger(DAOManager.class);
	
	private SqlSessionFactory sqlSessionFactory = null;
	
	public DAOManager() {
		String environment = System.getProperty("ENVIRONMENT");
		
		try {
			sqlSessionFactory = SqlSessionFactoryConfigurer.configureSqlSessionFactory(environment);
		}catch(Exception e){
			logger.error("An error occured", e);
			throw new RuntimeException(e);
		}
	}
	
	public SqlSession openSession() {
		SqlSession ret = this.sqlSessionFactory.openSession();
		
		return ret;
	}
}